import { createStore,combineReducers,applyMiddleware, compose} from 'redux'
import thunk from "redux-thunk";
//require.context(遍历的目录,是否递归遍历,正则表达式)
//根据指定目录获取目录下的东西
const files = require.context("./reducers",false,/\.js$/)

//通过keys方法获取需要的数组格式
console.log(files.keys());// ["./tool.js", "./user.js"]
let members = {}
files.keys().forEach((el) =>{
    let member = files(el).default;
    console.log(files(el));
    console.log(member);
    //获取文件名称(命名空间)
    let filename = el.replace(/(.*\/)*([^.]+).*/gi, "$2");
    members[filename] = member
})
console.log(members);// {tool: ƒ, user: ƒ}


//合并reducer
const reducers = combineReducers(members)
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(reducers,composeEnhancers(applyMiddleware(thunk)))
export default store
